function submitForm(form, url) {
    //封装对象
    var param = submitObject(form);
    //发送请求
    sendRequest(url, param);

}

function sendReqCallBack(param, url, callback) {

    //发送请求
    $.ajax({
        url: url,
        type: "POST",
        data: param,
        datatype: "JSON",
        success: function (data) {
            if (data.status == "success") {
                layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                    /*注册成功后，回调函数，跳转到主页*/
                    callback(data);
                });
            } else {
                layer.msg(data.msg, {icon: 2, time: 1000});
            }


        },
        error: function (data) {
            layer.msg(data.msg, {icon: 2, time: 1000})
        },
        //在请求发送之前调用
        beforeSend: function (XMLHttpRequest) {
            //获取token，通过请求传过去
            var token = localStorage.getItem("2009-login-token");
            if (token) {
                XMLHttpRequest.setRequestHeader("token", token);
            }
        }
    });
}

//发送请求
function sendRequest(url, param) {
    $.ajax({
        url: url,
        type: "POST",
        data: param,
        datatype: "JSON",
        success: function (data) {
            //服务端响应
            responseClient(data);
        }
    })
}

//响应客户端
function responseClient(data) {
    if (data.status == "success") {
        /*icon:1图形1，time：1s后关闭*/
        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
            //获取表单弹出的最新一层索引
            var index = parent.layer.getFrameIndex(window.name);
            //关闭窗口
            parent.layer.close(index);
        });

    } else {
        layer.msg(data.msg, {icon: 2, time: 1000})
    }

}

///获取form数据，封装成一个对象
function submitObject(form) {
    //把表单封装成一个对象
    //获取表单数据
    var array = form.serializeArray();
    //创建一个对象
    var param = new Object();
    //遍历数组
    for (var i = 0; i < array.length; i++) {
        //表单的name
        var n = array[i].name;
        //表单的vaule
        var v = array[i].value;
        // param.name="xxx";
        param[n] = v;

    }
    return param;
}